import 'package:flutter/material.dart';
import 'package:flutter_module/model/service_object_mo.dart';
import 'package:flutter_module/style/colors.dart';

class GridViewItemWidget extends StatefulWidget {
  final ServiceObjectMo bean;
  final Function? callback;

  const GridViewItemWidget({Key? key, required this.bean, this.callback})
      : super(key: key);

  @override
  _GridViewItemWidgetState createState() => _GridViewItemWidgetState();
}

class _GridViewItemWidgetState extends State<GridViewItemWidget> {
  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      child: Stack(
        alignment: Alignment.center,
        children: [
          Positioned(
            //点击事件
            child: GestureDetector(
              onTap: () {
                //相反取值
                widget.bean.nativeSelect = !widget.bean.nativeSelect!;
                if (widget.callback != null) {
                  widget.callback!();
                }
                setState(() {});
              },
              child: buildContainer(),
            ),
          )
        ],
      ),
    );
  }

  Container buildContainer() {
    return Container(
      //子Widget 居中
      alignment: Alignment.center,
      decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(3),
          border: Border.all(
              color: widget.bean.nativeSelect == true
                  ? ThemeColors.text_ef5d5e
                  : ThemeColors.grayE5E5E5,
              width: 1)),
      child: buildText(),
    );
  }

  buildText() {
    return Text(
      "${widget.bean.dictName}",
      style: widget.bean.nativeSelect==true
          ? _contentSelectStyle
          : _contentUnSelectStyle,
      maxLines: 1,
    );
  }

  final _contentSelectStyle =
      TextStyle(color: ThemeColors.text_ef5d5e, fontSize: 11, height: 1.7);
  final _contentUnSelectStyle =
      TextStyle(color: ThemeColors.text888, fontSize: 11, height: 1.7);
}
